import { getlink } from "@/api/getshopapi.js"

export let a = {
    state: {
        sta: false,
        totalmoney: 0,
        totalmoney1: 0,
        arr: []
    },
    mutations: {
        sta(state) {
            state.sta = !state.sta
        },
        add(state, payload) {
            console.log(state.totalmoney)
            state.totalmoney = Math.round(state.totalmoney + Number(payload.num))
        },
        reduce(state, payload) {
            console.log("--")
            console.log(state.totalmoney)
            state.totalmoney = Math.round(state.totalmoney - payload.num)
        },
        totalgoods(state, payload) {
            console.log("++")
            state.totalmoney = Math.round(state.totalmoney + Number(payload.num))
        },
        nogoods(state) {
            state.totalmoney = 0
        },
        uparr(state, payload) {
            state.arr = payload
        }
    },
    actions: {
        axiosshop(context, payload) {
            // 发送异步操作   拦截器与数据请求封装
            // getlink("/shop/haozi").then((ok) => {
            getlink(payload.url).then((ok) => {
                console.log(ok.data.arr)

                context.commit("uparr", ok.data.arr)
            })
        }
    }
}